package com.aiti.ai.config;



import com.google.common.util.concurrent.ThreadFactoryBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.*;


@Configuration
public class ThreadPoolConfig
{
    private int corePoolSize = 16;
    private int maxPoolSize = 32;
    private int queueCapacity = 64;
    private long keepAliveTime = 60;

    @Bean(name = "threadPoolExecutor")
    public ThreadPoolExecutor threadPoolTaskExecutor()
    {
        ThreadPoolExecutor executor = new ThreadPoolExecutor(
                corePoolSize,
                maxPoolSize,
                keepAliveTime,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(queueCapacity),
                new ThreadFactoryBuilder().setNameFormat("thirdparty-pool-%d").build(),
                new ThreadPoolExecutor.CallerRunsPolicy()
        );

        executor.allowCoreThreadTimeOut(true);
        return executor;
    }


}
